package com.sdstc.modules.vo;

import com.ruoyi.common.enums.OrganType;
import com.sdstc.modules.eneity.PlanEntity;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author ：wk
 * @date ：Created in 2022/11/25 9:52
 */
@Data
public class ScreenVo {

    // 机构
    private OrgScreen orgScreen;

    // 编制
    private OrganScreen organScreen;

    // 人员
    private PersonScreen personScreen;

    // 超空编
    private OverEmptyScreen overEmptyScreen;

    // 三级机构轮播
    List<OrgDetail> orgDetailList = new ArrayList<>();


    // 近期拟调整方案
    List<PlanEntity> planList = new ArrayList<>();

    @Data
    public static class OrgScreen {
        private Integer orgScreenTotal;
        private List<String> orgScreenName = new ArrayList<>();
        private List<Integer> orgScreenValue = new ArrayList<>();
    }

    @Data
    public static class OrganScreen {
        private List<EchartsDataVo> organScreenList = new ArrayList<>();
        private Integer organScreenTotal;
    }

    @Data
    public static class PersonScreen {

        private List<EchartsDataVo> personScreenList = new ArrayList<>();
        private Integer personScreenTotal;

    }

    @Data
    public static class OverEmptyScreen {

        // 超空编数
        private Integer overEmptyTotal;
        private List<EchartsDataVo> overEmptyScreenList = new ArrayList<>();

    }

    @Data
    public static class OrgDetail {

        // 机构名称
        private String orgName;

        // 编制详情
        List<OrganDetail> organDetailList = new ArrayList<>();


    }


    @Data
    public static class OrganDetail {

        // 编制类型
        private String organType;

        // 预设
        private Integer presets;

        // 实配
        private Integer real;
    }

    public OverEmptyScreen buildOverEmptyScreen(OrganScreen organScreen, PersonScreen personScreen){
        OverEmptyScreen overEmptyScreen = new OverEmptyScreen();
        Map<String, Integer> orgMap = organScreen.getOrganScreenList().stream().collect(Collectors.toMap(EchartsDataVo::getName, EchartsDataVo::getValue));
        Map<String, Integer> personMap = personScreen.getPersonScreenList().stream().collect(Collectors.toMap(EchartsDataVo::getName, EchartsDataVo::getValue));
        overEmptyScreen.setOverEmptyTotal(personScreen.getPersonScreenTotal() - organScreen.getOrganScreenTotal());
        EchartsDataVo admin = new EchartsDataVo();
        admin.setName(OrganType.ADMIN.getInfo());
        admin.setValue(personMap.get(OrganType.ADMIN.getInfo()) - orgMap.get(OrganType.ADMIN.getInfo()));
        overEmptyScreen.getOverEmptyScreenList().add(admin);
        EchartsDataVo single = new EchartsDataVo();
        single.setName(OrganType.SINGLE.getInfo());
        single.setValue(personMap.get(OrganType.SINGLE.getInfo()) - orgMap.get(OrganType.SINGLE.getInfo()));
        overEmptyScreen.getOverEmptyScreenList().add(single);
        EchartsDataVo work = new EchartsDataVo();
        work.setName(OrganType.WORK.getInfo());
        work.setValue(personMap.get(OrganType.WORK.getInfo()) - orgMap.get(OrganType.WORK.getInfo()));
        overEmptyScreen.getOverEmptyScreenList().add(work);
        EchartsDataVo cause = new EchartsDataVo();
        cause.setName(OrganType.CAUSE.getInfo());
        cause.setValue(personMap.get(OrganType.CAUSE.getInfo()) - orgMap.get(OrganType.CAUSE.getInfo()));
        overEmptyScreen.getOverEmptyScreenList().add(cause);
//        overEmptyScreen.setAdmin(personScreen.getPersonScreenList().get(0).getValue() - organScreen.getOrganScreenList().get(0).getValue());
//        overEmptyScreen.setSingle(personScreen.getPersonScreenList().get(1).getValue() - organScreen.getOrganScreenList().get(1).getValue());
//        overEmptyScreen.setWork(personScreen.getPersonScreenList().get(2).getValue() - organScreen.getOrganScreenList().get(2).getValue());
//        overEmptyScreen.setCause(personScreen.getPersonScreenList().get(3).getValue() - organScreen.getOrganScreenList().get(3).getValue());
        return overEmptyScreen;
    }

}
